
function [] = SETAS_SurfMap_mthlyanim(varname)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% THIS  IS THE MAIN ROUTINE TO PRODUCE AN ANIMATION OF THE SURFACE MAP OF 
% A SETAS MONTHLY MEAN VARIABLE 
%  
% INPUT: - varname  : a SETAS variable. Available options are 'temp or 
%                    'salt' 
%
% EXAMPLE: SETAS_SurfMap_mthlyanim('temp')
%
% Author: Benedicte Pasquer, IMOS/eMII (http://imos.org.au/)
% email: benedicte.pasquer@utas.edu.au
% May 2013   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
dirname = pwd ;
flist = dir(fullfile (dirname,'setas_simple_*.nc'));


k = length(flist);
animated(1,1,1,k) = 0;

for n = 1:length(flist)
    
       [frame] = SurfMapPlotsubroutine(fullfile(dirname,flist(n).name),varname);

 if n == 1
      [animated, cmap] = rgb2ind(frame.cdata, 256, 'nodither');
   else
      animated(:,:,1,n) = rgb2ind(frame.cdata, cmap, 'nodither');
 end
  clear frame
end

% OUTPUT FILE NAME
filename = strcat(varname,'_surfanim.gif');
% GENERATION OF THE ANIMATED GIF
imwrite(animated,cmap,filename,'DelayTime',.25,'Loopcount',Inf)

